package com.canaan.business.controller.pc.storehouse;

import com.canaan.business.domain.storehouse.WmsInOutStorage;
import com.canaan.business.service.storehouse.IWmsInOutStorageService;
import com.canaan.common.annotation.Log;
import com.canaan.common.core.controller.BaseController;
import com.canaan.common.core.domain.AjaxResult;
import com.canaan.common.core.page.TableDataInfo;
import com.canaan.common.enums.BusinessType;
import com.canaan.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 出入库记录Controller
 *
 * @author ruoyi
 * @date 2022-11-30
 */
@Api(tags = "出入库记录管理")
@RestController
@RequestMapping("/storehouse/inoutstock")
public class WmsInOutStorageController extends BaseController
{
    @Autowired
    private IWmsInOutStorageService wmsInOutStorageService;

    /**
     * 查询出入库记录列表
     */
    @ApiOperation("查询出入库记录列表")
    @GetMapping("/list")
    public TableDataInfo list(WmsInOutStorage wmsInOutStorage)
    {
        startPage();
        List<WmsInOutStorage> list = wmsInOutStorageService.selectWmsInOutStorageList(wmsInOutStorage);
        return getDataTable(list);
    }

    /**
     * 导出出入库记录列表
     */
    @ApiOperation(value = "导出出入库记录列表")
    @Log(title = "出入库记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WmsInOutStorage wmsInOutStorage)
    {
        List<WmsInOutStorage> list = wmsInOutStorageService.selectWmsInOutStorageList(wmsInOutStorage);
        ExcelUtil<WmsInOutStorage> util = new ExcelUtil<WmsInOutStorage>(WmsInOutStorage.class);
        util.exportExcel(response, list, "出入库记录数据");
    }

    /**
     * 获取出入库记录详细信息
     */
    @ApiOperation(value = "获取出入库记录详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(wmsInOutStorageService.selectWmsInOutStorageById(id));
    }

    /**
     * 新增出入库记录
     */
    @ApiOperation("新增出入库记录")
    @Log(title = "出入库记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody @Validated WmsInOutStorage wmsInOutStorage)
    {
        wmsInOutStorage.setCreateBy(getUsername());
        return toAjax(wmsInOutStorageService.insertWmsInOutStorage(wmsInOutStorage));
    }

    /**
     * 修改出入库记录
     */
    @ApiOperation("修改出入库记录")
    @Log(title = "出入库记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody @Validated WmsInOutStorage wmsInOutStorage)
    {
        return toAjax(wmsInOutStorageService.updateWmsInOutStorage(wmsInOutStorage));
    }

    /**
     * 删除出入库记录
     */
    @ApiOperation(value = "删除出入库记录")
    @Log(title = "出入库记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(wmsInOutStorageService.deleteWmsInOutStorageByIds(ids));
    }
}
